#include "Myqueue.hpp"
typedef void (*func)();
Myqueue<int> myq;
struct date
{
    string _name;
    func _f;
    date(const char *name, func f)
        : _name(name), _f(f)
    {
    }
};
void product()
{
    while (true)
    {
        sleep(1);
        myq.push(rand() % 10);
        //cout << "生产者插入数据" << endl;
    }
}
void custcom()
{
    while (true)
    {
        sleep(1);
        int x;
        myq.pop(x);
        cout << "消费者：" << x << endl;
    }
}
void *enter(void *args)
{
    date *td = reinterpret_cast<date *>(args);
    td->_f();
    return nullptr;
}
int main()
{
    srand((unsigned int)time(nullptr));
    pthread_t t1, t2;
    const char *str = "pthread product";
    const char *str2 = "pthread custcom";
    pthread_create(&t1, nullptr, enter, (void *)&date(str, product));
    pthread_create(&t2, nullptr, enter, (void *)&date(str2, custcom));
    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    cout << "回收线程成功" << endl;
    return 0;
}
